<template>
  <div>
    <el-form
      ref="form"
      :model="userinfo"
      :rules="rules"
      label-width="80px"
      :inline="false"
      size="normal"
    >
      <!-- 姓名 -->
      <el-form-item label="姓名" prop="name">
        <el-input v-model="userinfo.username" style="width: 300px" />
      </el-form-item>
      <!-- 密码 -->
      <el-form-item label="密码">
        <el-input v-model="userinfo.password" style="width: 300px" disabled />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitEdit">立即创建</el-button>
        <el-button @click="$router.back()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employees'
import { mapActions } from 'vuex'
export default {
  props: {
    userinfo: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    ...mapActions('user', ['getUserInfoAction']),
    async submitEdit () {
      try {
        await saveUserDetailById(this.userinfo)
        this.$message.success('修改成功')
        this.getUserInfoAction()
        this.$router.back()
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
